import CryptoJS from "crypto-js";

let KEY = 'duobakejiyyfu023';
let IV = 'EkpTEA3FbZlbh050';
let tools = {
  /*aes加密*/
  setAES(str) {
    let key = CryptoJS.enc.Utf8.parse(KEY); // 秘钥
    let iv = CryptoJS.enc.Utf8.parse(IV); //向量iv
    let encrypted = CryptoJS.AES.encrypt(str, key, {
      iv: iv,
      mode: CryptoJS.mode.CBC,
      padding: CryptoJS.pad.Pkcs7
    });
    return encrypted.toString();
  },
  /*aes解密*/
  decryptAES(str) {
    let key = CryptoJS.enc.Utf8.parse(KEY); // 秘钥
    let iv = CryptoJS.enc.Utf8.parse(IV); //向量iv
    let decryptedData = CryptoJS.AES.decrypt(str, key, {
      iv:iv,
      mode: CryptoJS.mode.CBC,
      padding: CryptoJS.pad.Pkcs7
    });
    var decryptedStr = decryptedData.toString(CryptoJS.enc.Utf8);
    return decryptedStr;
  }
};
 
export default tools;